package com.kkb.mybatis.phase1;

import com.kkb.mybatis.phase1.dao.UserDao;
import com.kkb.mybatis.phase1.dao.UserDapImpl;
import com.kkb.mybatis.phase1.po.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

/**
 * author: zsl
 * date: 2019/10/9 17:32
 * Description:
 */
public class Test1 {
    private SqlSessionFactory sqlSessionFactory;


    @Before
    public void dsd() throws IOException {

        String resourdes = "phase1/SqlMapConfig.xml";
        InputStream resourceAsStream = Resources.getResourceAsStream(resourdes);
        //sqlSessionFactory需要通过sqlSessionFactoryBuilder读取配置文件后使用
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
    }

//    @After
//    public void shy(){
//        System.out.println("事后烟");
//    }

    @Test
    public void mybatisTest(){
        UserDao userDao = new UserDapImpl(sqlSessionFactory);
        User userByOne = userDao.findUserByOne(1);
        System.out.println(userByOne);
    }

}